package game.editer.ui;

import hx.events.Event;
import game.editer.view.AlertView;
import game.editer.view.InputListDataView;
import game.editer.AttrEditer.AttrData;
import game.editer.view.CreateEffectPreviewView;
import game.editer.config.HitDataConfig;
import hx.events.MouseEvent;

/**
 * 特效属性选择输入支持
 */
class ObjectInput extends BaseAttributeInput {
	var button = new Button();

	var attr:Array<AttrData>;

	override function onInit() {
		super.onInit();
		button.text = "空";
		button.width = 110;
		button.addEventListener(MouseEvent.CLICK, (e) -> {
			var view = new InputListDataView(this.titleText, attr);
			view.data = this.value;
			view.show();
			view.addEventListener(AlertView.BUTTON_CLICK, (e:Event) -> {
				if (e.data == "确定") {
					view.done();
					this.onAttributeChange(this);
				}
			});
		});
		this.addChild(button);
	}

	override function set_value(value:Dynamic):Dynamic {
		if (value != null) {
			this.button.text = [
				for (item in attr) {
					item.key + ":" + Reflect.getProperty(value, item.key);
				}
			].join(",");
		} else {
			this.button.text = "空";
		}
		return super.set_value(value);
	}

	public function bindAttrData(array:Array<AttrData>):BaseAttributeInput {
		this.attr = array;
		return this;
	}
}
